﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class header : System.Web.UI.UserControl
{
    public int GetNoticeCount()
    {
        GetData gd = new GetData();
        int count = gd.GetUnReadPostNoticeCount(int.Parse(Session["uid"].ToString()));
        return count;
    }

    private void checklogin()
    {
        if (Session["username"] == null)
        {
            literaluser.Text = "<li><a href=\"Login.aspx?ref=" + Server.UrlEncode(Request.Url.ToString()) + "\">登陆</a></li><li><a href=\"Login.aspx\">注册</a></li>";
        }
        else
        {
            literaluser.Text = "<li><a href=\"Profile.aspx?type=avatar\">"+Session["nickname"]+"</a></li>";
            int count = GetNoticeCount();
            if (count == 0)
                literaluser.Text += "<li><a href=\"Notice.aspx?type=notice&page=1\">消息</a></li>";
            else
                literaluser.Text += "<li><a href=\"Notice.aspx?type=notice&page=1\">消息" + "(" + count + ")" + "</a></li>";
            if (Session["gid"].ToString() == "1")
                literaluser.Text += "<li><a href=\"Admin.aspx?type=forum\">管理</a></li>";
            literaluser.Text+="<li><a href=\"Logout.aspx\">退出</a></li>";
            
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        checklogin();
    }
}